from django.urls import path, include
from rest_framework import routers

from . import views


router = routers.DefaultRouter()
router.register('posts', views.PostViewSet, basename='post')

# print(router.urls)
# [<URLPattern '^posts/$' [name='post-list']>,
# <URLPattern '^posts\.(?P<format>[a-z0-9]+)/?$' [name='post-list']>,
# <URLPattern '^posts/(?P<slug>[^/.]+)/$' [name='post-detail']>,
# <URLPattern '^posts/(?P<slug>[^/.]+)\.(?P<format>[a-z0-9]+)/?$' [name='post-detail']>,
# <URLPattern '^$' [name='api-root']>,
# <URLPattern '^\.(?P<format>[a-z0-9]+)/?$' [name='api-root']>
# ]

urlpatterns = [
    path('posts/popular/', views.PopularPostsView.as_view(), name='popular-post-list'),
    path('posts/search/', views.SearchPostsView.as_view(), name='search-post-list'),
    # path('posts/archive/<int:year>/<int:month>/', views.archive_post_list_view, name='archive-post-list'),

    # 这里不使用<int:year>/<int:month/是想后端处理异常
    # 而不是让请求发送到
    # re_path('.*', TemplateView.as_view(template_name='index.html'))
    # TODO:让前端处理-直接返回404？？
    path('posts/archive/<str:year>/<str:month>/', views.ArchivePostsView.as_view(), name='archive-post-list'),
    path('posts/get_archives/', views.get_archives_view, name='get-archives'),
    path('posts/get_links/', views.get_links_view, name='get-links'),
    path('', include(router.urls)),
    path('categories/', views.CategoriesView.as_view(), name='category-list'),
    path('categories/<str:category_name>/', views.CategoryPostsView.as_view(), name='category-post-list'),
    path('tags/<str:tag_name>/', views.TagPostsView.as_view(), name='tag-post-list'),
]
